package com.woniuxy.main.handler;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniuxy.main.pojo.Vi_user_student;
import com.woniuxy.main.service.Vi_user_studentService;
import com.woniuxy.main.util.SessionUtil;

@Controller
@RequestMapping("/vi_user_student")
public class Vi_user_studentHandler {
	@Resource
	private Vi_user_studentService vi_user_studentService;

	public Vi_user_studentService getVi_user_studentService() {
		return vi_user_studentService;
	}

	public void setVi_user_studentService(Vi_user_studentService vi_user_studentService) {
		this.vi_user_studentService = vi_user_studentService;
	}

	@RequestMapping("/all")
	@ResponseBody
	public List<Vi_user_student> all() {
		List<Vi_user_student> result = vi_user_studentService.all();
		return result;
	}

	@RequestMapping("/selectByUid")
	@ResponseBody
	public Vi_user_student selectByUid(HttpServletRequest request) {
		//得到session
		 HttpSession session = request.getSession();
		// 得到uid
		 int uid = (int) session.getAttribute("uid"); 
		 //根据session中保存的uid去查询当前用户详情
		
//		int uid=(int)SessionUtil.getSession().getAttribute("uid");
		Vi_user_student result = vi_user_studentService.selectByUid(uid);
		return result;
	}
	
	@RequestMapping("/showStudentList")
	@ResponseBody
	public Map<String,Object> all(Integer page){
		//System.out.println("开始运行");
		int index = (page - 1) * 8;
		Map<String,Object> result=new HashMap<String,Object>();
		List<Vi_user_student> info=vi_user_studentService.showStudentList(index);
		result.put("form", info);
		//查询总页码
		int totalCount=vi_user_studentService.totalPage();
		int totalPage=totalCount % 8 == 0 ? totalCount / 8 : totalCount / 8 + 1;
		result.put("totalPage", totalPage);
		return result;
	}

}
